
enum RXPIN {
    //% block="GPIO8"
    8
}
enum TXPIN {
    //% block="GPIO7"
    7
}

enum baudRate {
    //% block="9600"
    9600
}

enum BTN {
    //% block="A"
    A,
    //% block="B"
    B,
    //% block="A+B"
    AB
}

//% color="#ff8000" iconWidth=50 iconHeight=40
namespace ESP32_TO_UART {
    //% block="初始化语音模块 引脚  RX[RXPIN] TX[TXPIN] 波特率[baudRate]"  blockType="command"
    //% TXPIN.shadow="dropdown" TXPIN.options="TXPIN" TXPIN.defl="GPIO8"
    //% RXPIN.shadow="dropdown" RXPIN.options="RXPIN" RXPIN.defl="GPIO7"
    //% baudRate.shadow="dropdown" baudRate.options="baudRate" baudRate.defl="baudRate.9600"
    export function ESP32_TO_UART_init(parameter: any, block: any) {
        let rx = parameter.RXPIN.code;
        let tx = parameter.TXPIN.code;
        let baudRate = parameter.baudRate.code;
        Generator.addInclude('ZCWL_ASRH', '#include <ZCWL_ASR.h>');
        Generator.addObject(`ZCWL_ASR_OBJ`, `ZCWL_ASR`, `asr;`);
        Generator.addSetup(`asr.init`, `asr.init(${baudRate});`);
    }

    //% block="添加关键词[GUANJIANCI]编号为[BIANHAO]" blockType="command"
    //% GUANJIANCI.shadow="string" GUANJIANCI.defl="kai deng"
    //% BIANHAO.shadow="number" BIANHAO.defl=1
    export function addCommand(parameter: any, block: any) {
        let GUANJIANCI = parameter.GUANJIANCI.code;
        let BIANHAO = parameter.BIANHAO.code;
        Generator.addCode(`asr.addCommand(${BIANHAO},${GUANJIANCI});`);
    } 

    //% block="设置完成开始识别"  blockType="command"
    export function starAsr(parameter: any, block: any) {
        Generator.addCode("asr.starAsr();", `asr.starAsr()`);
    }

    //% block="识别一次语音并获取编号"  blockType="reporter"
    export function ESP32_TO_UART_READ(parameter: any, block: any) {
        Generator.addCode(`asr.read()`, Generator.ORDER_UNARY_POSTFIX);
    }
}
